package de.jonasjelten.jcalc.mathExps;

import de.jonasjelten.jcalc.api.JCalc;
import de.jonasjelten.jcalc.exception.JMathematicalException;
import de.jonasjelten.jcalc.math.JNumber;
import de.jonasjelten.jcalc.math.JMathOps;

/**
 * π
 * Diese Klasse ist die JMathExp zu pi
 *
 * @author Jonas Jelten
 */
public class JPi extends JZeroArgMathExp implements Runnable {

    JNumber value;
    final int scale;

    public JPi(int scale, JCalc jcalc) {
        super(jcalc);
        this.scale = scale;
    }

    @Override
    public JNumber eval() throws JMathematicalException {
        super.jcalc.expgroup.addActive();
        JNumber res = new JNumber(JMathOps.getPi(scale));
        super.jcalc.expgroup.setInactive();
        return res;
    }

    @Override
    public String toString() {
        return "π(" + scale + " places)";
    }

    @Override
    public boolean isTrivial() {
        return false;
    }
}
